<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
        }

        h1 {
            color: #333;
            text-align: center;
        }
        .news-item {
            display: flex;
            flex-direction: column;
            margin-bottom: 20px;
        }
        .news-item h2 {
            color: #555;
        }
        .subTitle {
            text-align: center;
        }
        .subTitle span {
            color: #777;
        }
        .news-item > div {
            margin: 20px 10% 20px 10%;
            color: #777;
        }
        .separator {
            width: 80%;
            display: block;
            height: 1px;
            background-color: #555;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div id="app">
    <title>{{news.title}}</title>
    <h1>{{news.title}}</h1>
    <div class="separator"></div> <!-- 分割线 -->
    <div class="news-item">
        <div class="subTitle">
            <span>发布时间：{{news.createTime}}</span>
            <span>来源：{{news.source}}</span>
        </div>
        <div v-html="news.content"></div>
    </div>
</div>
<script type="text/javascript">
    var app = new Vue({
        el:"#app",
        data: {
            //新闻
            news: null
        },
        created(){
            // 获取新闻ID参数
            let urlParams = new URLSearchParams(window.location.search);
            let newsId = urlParams.get('id');

            axios.get("/search/"+newsId).then(function (response) {
                app.news = response.data;
            });
        }
    });
</script>
</body>
</html>